//
//  BQMineProblemController.m
//  BeeQuick
//
//  Created by student on 2017/7/12.
//  Copyright © 2017年 BecomeRich. All rights reserved.
//

#import "BQMineProblemController.h"
#import <Masonry.h>
#import "BQBQMineProblemModel.h"

@interface BQMineProblemController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)NSArray *modelArray;

@end

@implementation BQMineProblemController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self loadData];
    [self setupUI];
}

- (void)loadData{
    
    NSString *fileName = [[NSBundle mainBundle]pathForResource:@"BQMineProblemController.plist" ofType:nil];
    NSArray *tempArray = [NSArray arrayWithContentsOfFile:fileName];
    NSMutableArray *mutableArray = [NSMutableArray array];
    for (NSDictionary *dict  in tempArray) {
        BQBQMineProblemModel *model = [[BQBQMineProblemModel alloc]init];
        [model setValuesForKeysWithDictionary:dict];
        [mutableArray addObject:model];
    }
    self.modelArray = mutableArray.copy;
}

- (void)setupUI{
    
    UITableView *tableView = [[UITableView alloc]init];
    tableView.dataSource = self;
    tableView.delegate = self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"BQMineProblemControllerCell"];
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.view).offset(64);
        make.top.bottom.trailing.leading.equalTo(self.view);
    }];
}

#pragma __UITableViewDataSource__

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.modelArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BQMineProblemControllerCell" forIndexPath:indexPath];
    BQBQMineProblemModel *model = [[BQBQMineProblemModel alloc]init];
    model = self.modelArray[indexPath.row];
    cell.textLabel.text = model.title;
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_down_arrow"]];
    [cell.contentView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cell.contentView);
        make.trailing.equalTo(cell.contentView).offset(-20);
    }];
    return  cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
@end
